package com.sgq.dao;

import com.sgq.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author sgq
 * @since 2024-09-13
 */
@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    /**
     * 根据id判断权限是否被使用
     * @param id
     * @return
     */
    @Select("select count(1) from sys_role_permission where permission_Id = #{id}")
    int checkRoleIsUse(Long id);

    /**
     * 删除角色权限关系
     * @param roleId
     */
    @Delete("delete from sys_role_permission where role_id = #{roleId}")
    void deleteRolePermission(Long roleId);

    /**
     * 保存角色权限关系
     * @param roleId
     * @param permissionIds
     * @return
     */
    int saveRolePermission(@Param("roleId") Long roleId, @Param("permissionIds") List<Long> permissionIds);
}
